#!/usr/bin/php
<?php
//echo "\x1b[31mTesting\x1b[0m\n";
/*
echo "\x1b[1mTest1\x1b[0m  \x1b[31mTest1\x1b[0m\n";
echo "\x1b[3m\x1b[4m\x1b[7m\x1b[9m\x1b[1m\x1b[34mTest2\x1b[0m  \x1b[32mTest2\x1b[0m\n";

echo "\x1b[4mTest3\x1b[0m  \x1b[33mTest3\x1b[0m\n";
echo "\x1b[7mTest4\x1b[0m  \x1b[34mTest4\x1b[0m\n";
echo "\x1b[9mTest4\x1b[0m  \x1b[35mTest4\x1b[0m\n";
echo "\x1b[22mTest4\x1b[0m  \x1b[36mTest4\x1b[0m\n";
echo "\x1b[23mTest4\x1b[0m  \x1b[37mTest4\x1b[0m\n";
echo "\x1b[24mTest4\x1b[0m  \x1b[39mTest4\x1b[0m\n";
echo "\x1b[27mTest4\x1b[0m  \x1b[40mTest4\x1b[0m\n";
*/


Class ColorConsole
{
 var $str_result;

function ColorConsole($str,$fg="default",$bg="default",$bold=0,$italics=0,$underline=0,$inverse=0,$strikethrough=0)
{
$this->str_result="";
$this->Decode($str,$fg,$bg,$bold,$italics,$underline,$inverse,$strikethrough);	
}


function get()
{
	return $this->str_result;
}

function Append($str,$fg="default",$bg="default",$bold=0,$italics=0,$underline=0,$inverse=0,$strikethrough=0)
{
	$this->Decode($str,$fg,$bg,$bold,$italics,$underline,$inverse,$strikethrough);		
	return $this->str_result;
}


function Decode($str,$fg="default",$bg="default",$bold=0,$italics=0,$underline=0,$inverse=0,$strikethrough=0)
{
	$tmp=$this->str_result;
	$this->str_result=$str;
	if ($bold)
		{
			$this->str_result="\x1b[1m".$this->str_result;
		}
	if ($italics)
		{
			$this->str_result="\x1b[3m".$this->str_result;
		}
	if ($underline)
		{
			$this->str_result="\x1b[4m".$this->str_result;
		}

	if ($inverse)
		{
			$this->str_result="\x1b[7m".$this->str_result;
		}
	if ($strikethrough)
		{
			$this->str_result="\x1b[9m".$this->str_result;
		}

	
	switch ($bg) {
		case "black":
    			$this->str_result="\x1b[40m".$this->str_result;
    			break;
		case "red":
    			$this->str_result="\x1b[41m".$this->str_result;
    			break;
		case "green":
    			$this->str_result="\x1b[42m".$this->str_result;
    			break;
		case "yellow":
    			$this->str_result="\x1b[43m".$this->str_result;
    			break;
		case "blue":
    			$this->str_result="\x1b[44m".$this->str_result;
    			break;
		case "magenta":
    			$this->str_result="\x1b[45m".$this->str_result;
    			break;
		case "cyan":
    			$this->str_result="\x1b[46m".$this->str_result;
    			break;
		case "white":
    			$this->str_result="\x1b[47m".$this->str_result;
    			break;
		default:
//    			$this->str_result="\x1b[49m".$this->str_result;
	}

	switch ($fg) {
		case "black":
    			$this->str_result="\x1b[30m".$this->str_result;
    			break;
		case "red":
    			$this->str_result="\x1b[31m".$this->str_result;
    			break;
		case "green":
    			$this->str_result="\x1b[32m".$this->str_result;
    			break;
		case "yellow":
    			$this->str_result="\x1b[33m".$this->str_result;
    			break;
		case "blue":
    			$this->str_result="\x1b[34m".$this->str_result;
    			break;
		case "magenta":
    			$this->str_result="\x1b[35m".$this->str_result;
    			break;
		case "cyan":
    			$this->str_result="\x1b[36m".$this->str_result;
    			break;
		case "white":
    			$this->str_result="\x1b[37m".$this->str_result;
    			break;
		default:
//    			$this->str_result="\x1b[39m".$this->str_result;
	}

	$this->str_result=$tmp.$this->str_result."\x1b[0m";

	return $this->str_result;
}


}



$A = new ColorConsole(" Hello \n",$fg="red",$bg="black",1,0,1);

//var_dump($A);

echo $A->get();
echo $A->Append(" Hello -2  \n",$fg="cyan",$bg="yellow",1,0,1);

?>